#set(tableComment = table.getComment())
#set(primaryKeyType = table.getPrimaryKey().getPropertySimpleType())
#set(entityClassName = table.buildEntityClassName())
#set(entityVarName = firstCharToLowerCase(entityClassName))
#set(serviceVarName = firstCharToLowerCase(table.buildServiceClassName()))
package #(packageConfig.controllerPackage);

import com.vipboot.framework.common.domain.ResponseResult;
import com.vipboot.framework.common.validate.AddGroup;
import com.vipboot.framework.common.validate.EditGroup;
import com.vipboot.framework.mybatisflex.core.page.PageData;
import com.vipboot.framework.mybatisflex.core.page.PageQuery;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import #(packageConfig.entityPackage).#(entityClassName);
import #(packageConfig.servicePackage).#(table.buildServiceClassName());
#if(controllerConfig.restStyle)
import org.springframework.web.bind.annotation.RestController;
#else
import org.springframework.stereotype.Controller;
#end
#if(controllerConfig.superClass != null)
import #(controllerConfig.buildSuperClassImport());
#end
#if(withSwagger && swaggerVersion.getName() == "FOX")
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
#end
#if(withSwagger && swaggerVersion.getName() == "DOC")
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
#end
import java.util.List;

/**
 * #(tableComment) 控制层。
 *
 * @author #(javadocConfig.getAuthor())
 * @since #(javadocConfig.getSince())
 */
@RequiredArgsConstructor
#if(controllerConfig.restStyle)
@RestController
#else
@Controller
#end
#if(withSwagger && swaggerVersion.getName() == "FOX")
@Api("#(tableComment)接口")
#end
#if(withSwagger && swaggerVersion.getName() == "DOC")
@Tag(name = "#(tableComment)接口")
#end
@RequestMapping("#(table.buildControllerRequestMappingPrefix())/#(firstCharToLowerCase(entityClassName))")
public class #(table.buildControllerClassName()) #if(controllerConfig.superClass)extends #(controllerConfig.buildSuperClassName()) #end {

    private final #(table.buildServiceClassName()) #(serviceVarName);

    /**
    * 分页查询#(tableComment)。
    *
    * @param pageQuery 分页对象
    * @return 分页对象
    */
    @SaCheckPermission("#(firstCharToLowerCase(entityClassName)):list")
    @GetMapping("/page")
    public ResponseResult<PageData<#(entityClassName)Vo>> page(@ModelAttribute #(entityClassName)Param param,
                                                    @ModelAttribute PageQuery pageQuery) {
            return ResponseResult.ok(#(serviceVarName).page(param, pageQuery));
    }

    /**
     * 添加#(tableComment)。
     *
     * @param bo #(tableComment)
     */
    @SaCheckPermission("#(firstCharToLowerCase(entityClassName)):save")
    @PostMapping("/save")
    public ResponseResult<Void> save(@Validated(AddGroup.class)
                                 @RequestBody #(entityClassName)Param param) {
        return #(serviceVarName).save(param) ? ResponseResult.ok() : ResponseResult.error();
    }


    /**
     * 根据主键更新#(tableComment)。
     *
     * @param bo #(tableComment)
     */
    @SaCheckPermission("#(firstCharToLowerCase(entityClassName)):update")
    @PostMapping("/update")
    public ResponseResult<Void> update(@Validated(EditGroup.class)
                                   @RequestBody #(entityClassName)Param param) {
        return #(serviceVarName).update(param) ? ResponseResult.ok() : ResponseResult.error();
    }

    /**
     * 根据#(tableComment)主键获取详细信息。
     *
     * @param id #(tableComment)主键
     * @return #(tableComment)详情
     */
    @GetMapping("/getInfo/{id}")
    public ResponseResult<#(entityClassName)> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable #(primaryKeyType) id) {
        return #(serviceVarName).getInfoById(id) ? ResponseResult.ok() : ResponseResult.error();
    }

    /**
    * 根据主键删除#(tableComment)。
    *
    * @param id 主键
    */
    @SaCheckPermission("#(firstCharToLowerCase(entityClassName)):remove")
    @PostMapping("/remove/{id}")
    public ResponseResult<Void> remove(@NotNull(message = "主键不能为空")
                                   @PathVariable #(primaryKeyType) id) {
        return #(serviceVarName).removeById(id) ? ResponseResult.ok() : ResponseResult.error();
    }

}
